<template>
    <header>
        <div class="header-content">
            <span>IIFA国际投资理财协会</span>
            <div class="wrap">
                <span class="zs_search" @click="router.push('/search')">证书查询</span>
                <ul>

                    <li v-if="!isLogin">
                        <span @click="login">登录</span>
                        <span class="margin5p_lr">|</span>
                        <span @click="reg">注册</span>
                    </li>
                    <li class="dropdown" v-if="isLogin">
                        <el-dropdown>
                            <span class="el-dropdown-link" v-text="email"> 
                            </span>
                            <template #dropdown>
                                <el-dropdown-menu style="width: 200px; background-color: #f9f9f9;">
                                    <el-dropdown-item style="font-size:16px;text-align:center;"
                                        @click="info">个人中心</el-dropdown-item>
                                    <el-dropdown-item style="font-size:16px;text-align:center;"
                                        @click="logout">退出登录</el-dropdown-item>
                                </el-dropdown-menu>
                            </template>
                        </el-dropdown>

                    </li>
                    <li>
                        <img src="../assets/img/search.png" @click="search" alt="" srcset="">
                    </li>
                    <li>
                        <input type="text" placeholder="请输入">
                    </li>
                    <li>
                        
                        <el-dropdown>
                            <img src="../assets/img/wx.png"   alt="" srcset=""  >

                            <template #dropdown>
                            <el-dropdown-menu>
                                <img src="../assets/img/gzh.jpg" style="width: 180px;height: 180px;" class="image" alt="" srcset=""/> 
                            </el-dropdown-menu>
                            </template>
                        </el-dropdown>
                      
                    </li>

                </ul>
            </div>
            
        </div>
    </header>
</template>
<script setup lang="ts">
const router = useRouter();
import store from '@/store';
import eventBus from '../event/mitt'
  
    function login() {
    router.push("/login");
}

function search() {
    router.push("/searchTitle");
}
function reg() {
    router.push("/reg");
}
const isLogin = ref(false)

const email = ref<string>('')
eventBus.on("isLogin", (data: any) => {
    isLogin.value = data
})

eventBus.on("memberEmail", (data: any) => {
    isLogin.value = true
    email.value = data
})

// eventBus.on("memberInfo", (data: any) => {
//     memberInfoData.value = cloneDeep(data)
// })

// onMounted(async () => {
//     if (store.getters.getToken) {
//         const response = await memberInfoApi()
//         if (response.code === -1 || response.code === -2 || response.code === -3 || response.code === -4 || response.code === -5) {
//             isLogin.value = false
//         } else {
//             isLogin.value = true
//         }
//     } else {
//         isLogin.value = false
//         router.push("/")
//     } 
// })

function info() {
    router.push("/info")
}
function logout() {
    store.commit('REMOVE_TOKEN')
    isLogin.value = false
    router.push("/login")
}

</script>
<style scoped lang='less'>
.wrap {
    display: flex;
}

.zs_search {
    margin-right: 15px;
    cursor: pointer;
}

header {
    height: 40px;
    line-height: 40px;
    background: #003768;
    color: #fff;

    .header-content {
        width: 1300px;
        margin: auto;
        display: flex;
        justify-content: space-between;
  .img{
    text-align: center;
  }
  .image{
    width: 40px;
    height: 40px;
    margin: 0 auto;
    text-align: center;
  }
        .dropdown {
            padding: 12px 20px !important;
            background: none !important;

            span {
                color: #fff;
                font-size: 16px;
            }

            .el-dropdown-menu {
                width: 100px;
            }
        }

        ul {
            display: flex;
            justify-content: space-between;

            li {
                list-style: none;
            }

            li:first-child {
                background: #4d917b;
                padding: 0 20px;

                .margin5p_lr {
                    margin: 0 5px;
                }

                span {
                    cursor: pointer;
                }
            }

            li:nth-child(2) {
                width: 40px;
                height: 40px;
                background-color: #f7f7f7;
                display: flex;
                align-items: center;
                justify-content: center;

                img {
                    
                    width: 24px;
                    height: 24px;
                }
            }

            li:nth-child(3) {
                width: 145px;
                height: 40px;
                display: flex;

                input {
                    width: 100%;
                    height: 100%;
                    background-color: #f5f5f5;
                    outline: none;
                    border: 0;
                    padding-left: 10px;
                    box-sizing: border-box;
                }
            }

            li:last-child {
                width: 40px;
                height: 40px;
                background: #0079c1;
                display: flex;
                align-items: center;
                justify-content: center;

                img {
                    
                    width: 24px;
                }
            }
        }
    }
}
</style>
../event/mitt